package org.jeecg.modules.paycenter.channel.pufa;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.paycenter.channel.bankdocking.dto.Acc;
import org.jeecg.modules.paycenter.pay.dto.PayBillData;
import org.jeecg.modules.paycenter.service.BaseBankService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class PingAnBankService extends BaseBankService {
//    public static  final String CHANNEL = "8";
//
//    @Autowired
//    private IHyPfAccountService hyPfAccountService;
//
//    @Autowired
//    private PinganAccountService pinganAccountService;
//
//    @Value("${pingan.payUrl}")
//    private String payUrl;
//
//
//    public Result<?> getShippingInfos(List<HyShippingNote> hyShippingNotes,
//                                      Map<String, HyDriver> driverMaps,
//                                      Map<String, HyVehicle> vehicleMaps,
//                                      Map<String, HyCarrier> carrierMaps,
//                                      Map<String, PinganAccount> driverAccountBookMaps,
//                                      Map<String, PinganAccount> carrierAccountMaps,
//                                      Map<String, PinganAccount> companyAccountBookMaps
//    ){
//        Set<String> driverSet = new HashSet<>();
//        Set<String> vehicleSet = new HashSet<>();
//        Set<String> carrierSet = new HashSet<>();
//        Set<String> companySet = new HashSet<>();
//
//        for (HyShippingNote hyShippingNote : hyShippingNotes) {
//            driverSet.add(hyShippingNote.getDriverId());
//            vehicleSet.add(hyShippingNote.getVehicleId());
//            companySet.add(hyShippingNote.getCompanyId());
//            if ("2".equals(hyShippingNote.getPayType())) {
//                carrierSet.add(hyShippingNote.getCarrierId());
//            }
//        }
//        if(companySet.size() == 0){
//            return Result.error("分公司信息不存在");
//        }
//        List<HyCompany> hyCompanies = hyCompanyService.listByIds(companySet);
//        if(hyCompanies.size() != companySet.size()){
//            return Result.error("分公司信息不存在");
//        }
//        List<PinganAccount> companyAccounts = pinganAccountService.lambdaQuery()
//                .in(PinganAccount::getUid, companySet)
//                .eq(PinganAccount::getUtype, 9).list();
//        if (companyAccounts.size() != companySet.size()) {
//            return Result.error("公司钱包未开通");
//        }
//        for (PinganAccount companyAccount : companyAccounts) {
//            companyAccountBookMaps.put(companyAccount.getUid(),companyAccount);
//        }
//
//        if(driverSet.size() == 0){
//            return Result.error("司机信息不存在");
//        }
//        if(vehicleSet.size() == 0){
//            return Result.error("车辆信息不存在");
//        }
//
//        List<HyDriver> hyDrivers = hyDriverService.listByIds(driverSet);
//        if(hyDrivers.size() != driverSet.size()){
//            return Result.error("司机信息不存在");
//        }
//
//        List<HyVehicle> hyVehicles = hyVehicleService.listByIds(vehicleSet);
//        if(hyVehicles.size() != vehicleSet.size()){
//            return Result.error("车辆信息不存在");
//        }
//        List<HyCarrier> hyCarriers = null;
//        if(carrierSet.size() > 0) {
//            hyCarriers = hyCarrierService.listByIds(carrierSet);
//            if (hyCarriers.size() != carrierSet.size()) {
//                return Result.error("车队长信息不存在");
//            }
//            for (HyCarrier hyCarrier : hyCarriers) {
//                carrierMaps.put(hyCarrier.getId(), hyCarrier);
//            }
//
//            List<PinganAccount> carrierAccounts =  pinganAccountService.lambdaQuery()
//                    .in(PinganAccount::getUid, carrierSet)
//                    .eq(PinganAccount::getUtype, 5)
//                    .list();
//
//            if (carrierAccounts.size() != carrierSet.size()) {
//                return Result.error("车队长钱包未开通");
//            }
//            for (PinganAccount account : carrierAccounts) {
//                carrierAccountMaps.put(account.getUid(), account);
//            }
//        }
//
//        for (HyDriver hyDriver : hyDrivers) {
//            driverMaps.put(hyDriver.getId(),hyDriver);
//        }
//
//        for (HyVehicle hyVehicle : hyVehicles) {
//            vehicleMaps.put(hyVehicle.getId(),hyVehicle);
//        }
//
//        List<PinganAccount> driverAccounts =  pinganAccountService.lambdaQuery()
//                .in(PinganAccount::getUid, driverSet)
//                .eq(PinganAccount::getUtype, 4)
//                .list();
//        for (PinganAccount account : driverAccounts) {
//            driverAccountBookMaps.put(account.getUid(), account);
//        }
//
//        if (driverAccounts.size() != driverSet.size()) {
//            List<String> noAccDriverList = new ArrayList<>();
//            List<String> noAccDriverIdList = new ArrayList<>();
//            for (HyDriver hyDriver : hyDrivers) {
//                if (!driverAccountBookMaps.containsKey(hyDriver.getId())) {
//                    noAccDriverList.add(hyDriver.getDriverName());
//                    noAccDriverIdList.add(hyDriver.getId());
//                }
//            }
//            return Result.error(-99,String.join(",", noAccDriverList) + ":等司机未开通钱包" , String.join(",", noAccDriverIdList));
//        }
//
//        return Result.OK();
//    }
//
//    public PayBillData createPayData(HyShippingNote hyShippingNote, PinganAccount companyAccountBook, PinganAccount customerAccountBook, HyDriver driver, PinganAccount driverAccountBook, HyVehicle vehicle, HyCarrier carrier, PinganAccount carrierAccountBook) {
//        PayBillData payBillData = new PayBillData();
//        //货主钱包
//        String customerDbAccNo = customerAccountBook.getSubAccount();
//        String customerDbAccName = customerAccountBook.getSubAccountName();
//        //分公司子账号
//        String companyAccNo = companyAccountBook.getSubAccount();
//        String companyAccName = companyAccountBook.getSubAccountName();
//        //司机账簿
//        String driverAccNo = driverAccountBook.getSubAccount();
//        String driverAccName = driverAccountBook.getSubAccountName();
//
//        HyCustomerBill customerBill = this.createCustomerBill(hyShippingNote);
//        customerBill.setDbaccno(customerDbAccNo);
//        customerBill.setDbaccname(customerDbAccName);
//        customerBill.setDblogaccno("");
//        customerBill.setDbProv("");
//        customerBill.setCraccno(companyAccNo);
//        customerBill.setCraccname(companyAccName);
//        customerBill.setCrlogaccno("");
//        customerBill.setCrProv("");
//
//        //添加运单支付流水单,分公司到司机
//        HyShippingNoteBill shippingNoteBill = this.createShippingBill(hyShippingNote, driver, vehicle);
//        //分公司
//        shippingNoteBill.setDbaccno(companyAccNo);
//        shippingNoteBill.setDbaccname(companyAccName);
//        shippingNoteBill.setDblogaccno("");
//        shippingNoteBill.setDbProv("");
//        //添加公司支付司机流水单
//        shippingNoteBill.setCraccno(driverAccNo);
//        shippingNoteBill.setCraccname(driverAccName);
//        shippingNoteBill.setCrlogaccno("");
//        shippingNoteBill.setCrProv("");
//        shippingNoteBill.setBankCode("");
//
//        //添加司机流水单
//        HyDriverBill driverBill = this.createDriverBill(hyShippingNote, driver, shippingNoteBill);
//        driverBill.setDbaccno(companyAccNo);
//        driverBill.setDbaccname(companyAccName);
//        driverBill.setDblogaccno("");
//        driverBill.setCraccno(driverAccNo);
//        driverBill.setCraccname(driverAccName);
//        driverBill.setCrlogaccno("");
//
//        //运费支付方式(1按运单结算2车队长结算)
//        HyCarrierBill carrierBill = null;
//        String payType = hyShippingNote.getPayType();
//        if ("1".equals(payType) || "3".equals(payType)) {
//            driverBill.setBillType("1");//司机支付运费
//        } else {
//            driverBill.setBillType("3");//车队长代收
//            String carrierAccNo = carrierAccountBook.getSubAccount();
//            String carrierAccName = carrierAccountBook.getSubAccountName();
//
//            carrierBill = this.createCarrierBill(hyShippingNote, driver, carrier);
//            carrierBill.setDbaccno(driverAccNo);
//            carrierBill.setDbaccname(driverAccName);
//            carrierBill.setDblogaccno("");
//            carrierBill.setDbProv("");
//            carrierBill.setCraccno(carrierAccNo);
//            carrierBill.setCraccname(carrierAccName);
//            carrierBill.setCrlogaccno("");
//            carrierBill.setCrBankCode("");
//        }
//        payBillData.setCustomerBill(customerBill);
//        payBillData.setShippingNoteBill(shippingNoteBill);
//        payBillData.setDriverBill(driverBill);
//        payBillData.setCarrierBill(carrierBill);
//        payBillData.setShippingNote(hyShippingNote);
//        return payBillData;
//    }
//
//    public void savePayData(PayBillData payBillData){
//        HyShippingNote shippingNote = payBillData.getShippingNote();
//        if (!hyShippingNoteService.updateById(shippingNote)) {
//            throw new JeecgBootException("运单添加支付信息失败");
//        }
//
//        HyCustomerBill customerBill = payBillData.getCustomerBill();
//        if (!hyCustomerBillService.save(customerBill)) {
//            throw new JeecgBootException("货主添加支付信息失败");
//        }
//
//        HyDriverBill driverBill = payBillData.getDriverBill();
//        if (!hyDriverBillService.save(driverBill)) {
//            throw new JeecgBootException("司机添加支付信息失败");
//        }
//
//        HyShippingNoteBill shippingNoteBill = payBillData.getShippingNoteBill();
//        if (!hyShippingNoteBillService.save(shippingNoteBill)) {
//            throw new JeecgBootException("运单流水添加支付信息失败");
//        }
//        HyCarrierBill carrierBill = payBillData.getCarrierBill();
//        if(carrierBill != null) {
//            if (!hyCarrierBillService.save(carrierBill)) {
//                throw new JeecgBootException("车队长添加支付信息失败");
//            }
//        }
//    }
//
//    /**
//     * 平台垫付
//     * @param payBillDataList
//     */
//    public Result platePostPay(List<PayBillData> payBillDataList) {
//
//        List<Result> resultList = new ArrayList<>();
//
//        for (PayBillData payBillData : payBillDataList) {
//            Result resultItem = new Result();
//            try{
//                resultItem = pay(payBillData);
//                resultList.add(resultItem);
//            }catch (Exception e){
//                HyShippingNote shippingNote = payBillData.getShippingNote();
//                shippingNote.setShippingPayStatus("7");
//                shippingNote.setBillPayRemark(e.getMessage());
//                hyShippingNoteService.updateById(shippingNote);
//            }
//        }
//        return Result.OK(resultList);
//
////        for (PayBillData payBillData : payBillDataList) {
////            this.pay(payBillData);
////        }
//    }
//
//    public Result pay(PayBillData payBillData) {
//        try{
//            //TODO 有问题需要该
//            //开始远程调用
//            log.info("pay----start--------- \n 入参为：" + JSONUtil.parseObj(payBillData));
//            String result = HttpRequest.post(payUrl)
//                    .header("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODE5NjgyNzUsInVzZXJuYW1lIjoiMTU2MzMxOTEzNzgifQ.5svJFZqrqVLaMWk-VbQQKeHdr5pIWVe8G04XJeXGwwE")
//                    .body(JSONUtil.parseObj(payBillData))
//                    .timeout(200000)//超时，毫秒
//                    .execute().body();
//            log.info("pay----end--------- \n 出参为：" + JSONUtil.parseObj(result));
//            if (ObjectUtil.isNotNull(result) && "0".equalsIgnoreCase(JSONUtil.parseObj(result).get("code").toString())) {
//                return Result.OK("支付成功", payBillData.getShippingNote().getShippingNoteNumber());
//            } else {
//                return Result.error("支付失败："+JSONUtil.parseObj(result).get("msg"), payBillData.getShippingNote().getShippingNoteNumber());
//            }
//        }catch (Exception e){
//            HyShippingNote shippingNote = payBillData.getShippingNote();
//            shippingNote.setShippingPayStatus("7");
//            shippingNote.setBillPayRemark(e.getMessage());
//            hyShippingNoteService.updateById(shippingNote);
//        }
//        return Result.error("支付失败"+ payBillData.getShippingNote().getShippingNoteNumber());
//    }
//    public Result payBatch(List<PayBillData> payBillDataList) {
//
//        List<Result> resultList = new ArrayList<>();
//
//        for (PayBillData payBillData : payBillDataList) {
//            Result resultItem = new Result();
//            try{
//                resultItem = pay(payBillData);
//                resultList.add(resultItem);
//            }catch (Exception e){
//                HyShippingNote shippingNote = payBillData.getShippingNote();
//                shippingNote.setShippingPayStatus("7");
//                shippingNote.setBillPayRemark(e.getMessage());
//                hyShippingNoteService.updateById(shippingNote);
//            }
//        }
//        return Result.OK(resultList);
//    }
//
//    public void repay(HyShippingNote hyShippingNote) {
//
//        String shipping_id = hyShippingNote.getId();
//        PayBillData payBillData = new PayBillData();
//        payBillData.setShippingNote(hyShippingNote);
//
//        HyShippingNoteBill shippingNoteBill = hyShippingNoteBillService.getBillByShippingId(shipping_id);
//        HyDriverBill driverBill = hyDriverBillService.getBillByShippingId(shipping_id);
//
//        HyCustomerBill customerBill = hyCustomerBillService.getBillByShippingId(shipping_id,hyShippingNote.getCustomerId());
//
//        if(customerBill==null){
//            throw new JeecgBootException("支付流水单信息不存在");
//        }
//        String customerBillRespSource = customerBill.getRespSource();
//        if("-1".equals(customerBillRespSource) ||"-2".equals(customerBillRespSource)){
//            throw new JeecgBootException("支付异常，需人工处理");
//        }
//        if ("5".equals(customerBillRespSource)) {
//            customerBill.setRespSource(null);
//            String customerBillNum = CodeUtil.getBillNum();
//            customerBill.setBillNum(customerBillNum);//设置支付流水单
//            customerBill.setPayDt(new Date());//支付时间
//            if (!hyCustomerBillService.updateById(customerBill)) {
//                throw new JeecgBootException("添加支付信息失败");
//            }
//
//        }
//        String driverBillRespSource = driverBill.getRespSource();
//        if("-1".equals(driverBillRespSource) ||"-2".equals(driverBillRespSource)){
//            throw new JeecgBootException("支付异常，需人工处理");
//        }
//
//        String shippingNoteBillRespSource = shippingNoteBill.getRespSource();
//        if("-1".equals(shippingNoteBillRespSource) ||"-2".equals(shippingNoteBillRespSource)){
//            throw new JeecgBootException("支付异常，需人工处理");
//        }
//        if ("5".equals(shippingNoteBillRespSource)) {
//            String shippingNoteBillNum = CodeUtil.getBillNum();
//            shippingNoteBill.setRespSource(null);
//            shippingNoteBill.setBillNum(shippingNoteBillNum);
//            shippingNoteBill.setPayDt(new Date());//支付时间
//            driverBill.setRespSource(null);
//            driverBill.setBillNum(shippingNoteBillNum);//流水单号
//            if (!hyShippingNoteBillService.updateById(shippingNoteBill)) {
//                throw new JeecgBootException("添加支付信息失败");
//            }
//            if (!hyDriverBillService.updateById(driverBill)) {
//                throw new JeecgBootException("添加支付信息失败");
//            }
//        }
//        payBillData.setCustomerBill(customerBill);
//        payBillData.setDriverBill(driverBill);
//        payBillData.setShippingNoteBill(shippingNoteBill);
//
//        String payType = hyShippingNote.getPayType();
//        if ("2".equals(payType)) {
//            HyCarrierBill carrierBill = hyCarrierBillService
//                    .getOne(new QueryWrapper <HyCarrierBill>().eq("shipping_id", shipping_id));
//            String carrierBillRespSource = carrierBill.getRespSource();
//            if("-1".equals(carrierBillRespSource) ||"-2".equals(carrierBillRespSource)){
//                throw new JeecgBootException("支付异常，需人工处理");
//            }
//            if ("5".equals(carrierBill.getRespSource())) {
//                String carrierBillNum = CodeUtil.getBillNum();
//                carrierBill.setRespSource(null);
//                carrierBill.setBillNum(carrierBillNum);
//                if (!hyCarrierBillService.updateById(carrierBill)) {
//                    throw new JeecgBootException("添加支付信息失败");
//                }
//            }
//            payBillData.setCarrierBill(carrierBill);
//        }
//
//        if (!hyShippingNoteService.updateById(hyShippingNote)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        this.pay(payBillData);
//    }
//
//    public List<PayBillData> createPayDatas(List<HyShippingNote> hyShippingNotes, PinganAccount customerAccountBook, Map<String, PinganAccount> companyAccountBookMaps,
//                                            Map<String, HyDriver> driverMaps, Map<String, HyVehicle> vehicleMaps, Map<String, HyCarrier> carrierMaps,
//                                            Map<String, PinganAccount> driverAccountBookMaps, Map<String, PinganAccount> carrierAccountBookMaps) {
//        String realName = UserUtil.getLoginUser().getRName();
//        List<PayBillData> payBillDatas = new ArrayList<>();
//        for (HyShippingNote hyShippingNote : hyShippingNotes) {
//            //设置付款人信息
//            hyShippingNote.setBillPayStatus("1");//开始支付
//            hyShippingNote.setShippingPayStatus("5");
//            hyShippingNote.setPayDt(new Date());//申请运费支付时间
//            hyShippingNote.setFkr(realName);//设置付款人
//            hyShippingNote.setPayChannel(CHANNEL);
//            hyShippingNote.setPaySource(CHANNEL);
//            PinganAccount companyAccountBook = companyAccountBookMaps.get(hyShippingNote.getCompanyId());
//            HyDriver driver = driverMaps.get(hyShippingNote.getDriverId());
//            HyVehicle vehicle = vehicleMaps.get(hyShippingNote.getVehicleId());
//            PinganAccount driverAccountBook = driverAccountBookMaps.get(hyShippingNote.getDriverId());
//            HyCarrier carrier = null;
//            PinganAccount CarrierAccountBook = null;
//            String payType = hyShippingNote.getPayType();
//            if ("2".equals(payType)) {
//                carrier = carrierMaps.get(hyShippingNote.getCarrierId());
//                CarrierAccountBook =carrierAccountBookMaps.get(hyShippingNote.getCarrierId());
//            }
//            PayBillData payBillData = this.createPayData(hyShippingNote, companyAccountBook, customerAccountBook, driver, driverAccountBook, vehicle, carrier,CarrierAccountBook);
//            payBillDatas.add(payBillData);
//        }
//
//        //更新数据
//        if (!hyShippingNoteService.updateBatchById(hyShippingNotes)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//
//        List<HyCustomerBill> customerBills = new ArrayList<>();
//        List<HyShippingNoteBill> shippingNoteBills = new ArrayList<>();
//        List<HyDriverBill> driverBills = new ArrayList<>();
//        List<HyCarrierBill> carrierBills = new ArrayList<>();
//        for (PayBillData payBillData : payBillDatas) {
//            HyCustomerBill customerBill = payBillData.getCustomerBill();
//            HyShippingNoteBill shippingNoteBill = payBillData.getShippingNoteBill();
//            HyDriverBill driverBill = payBillData.getDriverBill();
//            HyCarrierBill carrierBill = payBillData.getCarrierBill();
//            customerBills.add(customerBill);
//            shippingNoteBills.add(shippingNoteBill);
//            driverBills.add(driverBill);
//            if (carrierBill != null) {
//                carrierBills.add(carrierBill);
//            }
//        }
//        if (!hyCustomerBillService.saveBatch(customerBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (!hyShippingNoteBillService.saveBatch(shippingNoteBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (!hyDriverBillService.saveBatch(driverBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (carrierBills.size() > 0) {
//            if (!hyCarrierBillService.saveBatch(carrierBills)) {
//                throw new JeecgBootException("添加支付信息失败");
//            }
//        }
//        return payBillDatas;
//    }
//
//    public Result<?> getDriverAccounts(Map<String, HyDriver> driverMaps) {
//        Map<String, PinganAccount> driverAccountBookMaps = new HashMap<>();
//        Set<String> driverSet = driverMaps.keySet();
//        Collection<HyDriver> hyDrivers = driverMaps.values();
//        List<PinganAccount> driverAccountBooks = pinganAccountService.lambdaQuery()
//                .in(PinganAccount::getUid, driverSet)
//                .list();
//        for (PinganAccount driverAccountBook : driverAccountBooks) {
//            driverAccountBookMaps.put(driverAccountBook.getUid(), driverAccountBook);
//        }
//        if (driverAccountBooks.size() != driverSet.size()) {
//            List<String> noAccDriverList = new ArrayList<>();
//            List<String> noAccDriverIdList = new ArrayList<>();
//            for (HyDriver hyDriver : hyDrivers) {
//                if (!driverAccountBookMaps.containsKey(hyDriver.getId())) {
//                    noAccDriverList.add(hyDriver.getDriverName());
//                    noAccDriverIdList.add(hyDriver.getId());
//                }
//            }
//            return Result.error(-98, String.join(",", noAccDriverList) + ":等司机未开通钱包", String.join(",", noAccDriverIdList));
//        }
//        return Result.OK(driverAccountBookMaps);
//    }
//
//    public Map<String, PinganAccount> getCarrierAccounts(Map<String, HyCarrier> carrierMaps) {
//        Map<String, PinganAccount> carrierAccountBookHashMaps = new HashMap<>();//车队长钱包
//        Set<String> carrierKeys = carrierMaps.keySet();
//        for (String carrierId : carrierKeys) {
//            HyCarrier hyCarrier = carrierMaps.get(carrierId);
//            PinganAccount carrierAccountBook = pinganAccountService.lambdaQuery()
//                    .eq(PinganAccount::getUid, carrierId)
//                    .one();
//            if (carrierAccountBook == null) {
////                return Result.error("车队长:" + hyCarrier.getCarrierName() + ",未开通钱包");
//                throw new JeecgBootException("车队长:" + hyCarrier.getCarrierName() + ",未开通钱包");
//            }
//            carrierAccountBookHashMaps.put(carrierId, carrierAccountBook);
//        }
//        return carrierAccountBookHashMaps;
//    }
//
//
//    public Result<?> checkPlatformAcc(BigDecimal totalAmt) {
//        //验证支付
//        PinganAccount platformAccountBook = pinganAccountService.lambdaQuery().eq(PinganAccount::getUid, "1").one();
//        if (platformAccountBook == null) {
//            return Result.error("尚未开通钱包功能!");
//        }
//        return Result.OK(platformAccountBook);
//    }
//
//
//    public List<PayBillData> createPlateformPayData(List<HyShippingNote> hyShippingNotes, BigDecimal totalAmt, String customerId,
//                                                    PinganAccount platformAccountBook,
//                                                    Map<String, HyCompany> companyMaps,
//                                                    Map<String, HyDriver> driverMaps,
//                                                    Map<String, HyVehicle> vehicleMaps,
//                                                    Map<String, HyCarrier> carrierMaps,
//                                                    Map<String, PinganAccount> driverAccountBookMaps,
//                                                    Map<String, PinganAccount> carrierAccountBookHashMaps
//    ) {
//        String realName = UserUtil.getLoginUser().getRName();
//        HyPlatformCost platformCost = new HyPlatformCost();
//        platformCost.setCustomerId(customerId);
//        platformCost.setCustomerBillNums(hyShippingNotes.size());
//        platformCost.setSt("0");
//        platformCost.setPayChannel(CHANNEL);
//        platformCost.setAmt(totalAmt);
//        if (!hyPlatformCostService.save(platformCost)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        String platformCostId = platformCost.getId();
//        List<PayBillData> payBillDatas = new ArrayList<>();
//        for (HyShippingNote hyShippingNote : hyShippingNotes) {
//            //运费支付方式(1按运单结算2车队长结算)
//            String payType = hyShippingNote.getPayType();
//            HyStatusCheckUtil.checkPayType(payType);
//            hyShippingNote.setBillPayStatus("1");//开始支付
//            hyShippingNote.setShippingPayStatus("5");
//            hyShippingNote.setPayDt(new Date());//申请运费支付时间
//            hyShippingNote.setFkr(realName);//设置付款人
//            hyShippingNote.setPayChannel(CHANNEL);
//            hyShippingNote.setPaySource("2");//平台垫付
//            hyShippingNote.setPlatformCostId(platformCostId);//垫付id
//            HyCompany company = companyMaps.get(hyShippingNote.getCompanyId());
//            HyDriver driver = driverMaps.get(hyShippingNote.getDriverId());
//            HyVehicle vehicle = vehicleMaps.get(hyShippingNote.getVehicleId());
//            PinganAccount driverAccountBook = driverAccountBookMaps.get(hyShippingNote.getDriverId());
//            HyCarrier carrier = null;
//            PinganAccount carrierAccountBook = null;
//            if ("2".equals(payType)) {
//                carrier = carrierMaps.get(hyShippingNote.getCarrierId());
//                carrierAccountBook = carrierAccountBookHashMaps.get(hyShippingNote.getCarrierId());
//            }
//            PayBillData payBillData = this.CreatePlateformPayItemData(platformCostId, payType, hyShippingNote, company, platformAccountBook, driver, driverAccountBook, vehicle, carrier, carrierAccountBook);
//            payBillDatas.add(payBillData);
//        }
//        //更新数据
//        if (!hyShippingNoteService.updateBatchById(hyShippingNotes)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//
//        List<HyCustomerBill> customerBills = new ArrayList<>();
//        List<HyShippingNoteBill> shippingNoteBills = new ArrayList<>();
//        List<HyDriverBill> driverBills = new ArrayList<>();
//        List<HyCarrierBill> carrierBills = new ArrayList<>();
//        for (PayBillData payBillData : payBillDatas) {
//            HyCustomerBill customerBill = payBillData.getCustomerBill();
//            HyShippingNoteBill shippingNoteBill = payBillData.getShippingNoteBill();
//            HyDriverBill driverBill = payBillData.getDriverBill();
//            HyCarrierBill carrierBill = payBillData.getCarrierBill();
//            customerBills.add(customerBill);
//            shippingNoteBills.add(shippingNoteBill);
//            driverBills.add(driverBill);
//            if (carrierBill != null) {
//                carrierBills.add(carrierBill);
//            }
//        }
//        if (!hyCustomerBillService.saveBatch(customerBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (!hyShippingNoteBillService.saveBatch(shippingNoteBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (!hyDriverBillService.saveBatch(driverBills)) {
//            throw new JeecgBootException("添加支付信息失败");
//        }
//        if (carrierBills.size() > 0) {
//            if (!hyCarrierBillService.saveBatch(carrierBills)) {
//                throw new JeecgBootException("添加支付信息失败");
//            }
//        }
//        return payBillDatas;
//    }
//
//
//    public PayBillData CreatePlateformPayItemData(String platformCostId, String payType, HyShippingNote hyShippingNote, HyCompany company, PinganAccount platformAccountBook, HyDriver driver, PinganAccount driverAccountBook, HyVehicle vehicle, HyCarrier carrier, PinganAccount carrierAccountBook) {
//        PayBillData payBillData = new PayBillData();
//        //添加货主支付公司流水单
//        //平台账号
//        String platformDbAccNo = platformAccountBook.getSubAccount();
//        String platformDbAccName = platformAccountBook.getSubAccountName();
////        String platformDbLogAccNo = platformAccountBook.getLogAccNo();
//
//        //分公司子账号
//        String companyAccNo = company.getAccNo();
//        String companyAccName = company.getAccName();
//        String companyLogAccNo = "";
//
//        //司机账簿
//        String driverAccNo = driverAccountBook.getSubAccount();
//        String driverAccName = driverAccountBook.getSubAccountName();
////        String driverLogAccNo = driverAccountBook.getLogAccNo();
//
//        HyCustomerBill customerBill = this.createCustomerBill(hyShippingNote);
//        customerBill.setBillType("2"); //平台垫付运费
//        customerBill.setPlatformCostId(platformCostId);//设置垫付运费id
//        //平台
//        customerBill.setDbaccno(platformDbAccNo);
//        customerBill.setDbaccname(platformDbAccName);
////        customerBill.setDblogaccno(platformDbLogAccNo);
////        customerBill.setDbProv(platformAccountBook.getProv());
//        //分公司
//        customerBill.setCraccno(companyAccNo);
//        customerBill.setCraccname(companyAccName);
//        customerBill.setCrlogaccno(companyLogAccNo);
//        customerBill.setCrProv(company.getProv());
//
//        //添加运单支付流水单
//        HyShippingNoteBill shippingNoteBill = this.createShippingBill(hyShippingNote, driver, vehicle);
//        //分公司
//        shippingNoteBill.setDbaccno(companyAccNo);
//        shippingNoteBill.setDbaccname(companyAccName);
//        shippingNoteBill.setDblogaccno(companyLogAccNo);
//        shippingNoteBill.setDbProv(company.getProv());
//
//        shippingNoteBill.setCraccno(driverAccNo);
//        shippingNoteBill.setCraccname(driverAccName);
////        shippingNoteBill.setCrlogaccno(driverLogAccNo);
////        shippingNoteBill.setCrProv(driverAccountBook.getProv());
//        shippingNoteBill.setBankCode("PINGAN");
//
//        //添加司机流水单
//        HyDriverBill driverBill = this.createDriverBill(hyShippingNote, driver, shippingNoteBill);
//        driverBill.setDbaccno(companyAccNo);
//        driverBill.setDbaccname(companyAccName);
//        driverBill.setDblogaccno(companyLogAccNo);
//        driverBill.setCraccno(driverAccNo);
//        driverBill.setCraccname(driverAccName);
////        driverBill.setCrlogaccno(driverLogAccNo);
//
//        //运费支付方式(1按运单结算2车队长结算)
//        HyCarrierBill carrierBill = null;
//        if ("1".equals(payType) || "3".equals(payType)) {
//            driverBill.setBillType("1");//司机支付运费
//        } else {
//            driverBill.setBillType("3");//车队长代收
//            //添加车队长流水单 (司机支付给车队长)
//            String carrierAccNo = carrierAccountBook.getSubAccount();
//            String carrierAccName = carrierAccountBook.getSubAccountName();
////            String carrierLogAccNo = carrierAccountBook.getLogAccNo();
//
//            carrierBill = this.createCarrierBill(hyShippingNote, driver, carrier);
//            carrierBill.setDbaccno(driverAccNo);
//            carrierBill.setDbaccname(driverAccName);
////            carrierBill.setDblogaccno(driverLogAccNo);
////            carrierBill.setDbProv(driverAccountBook.getProv());
//            carrierBill.setCraccno(carrierAccNo);
//            carrierBill.setCraccname(carrierAccName);
////            carrierBill.setCrlogaccno(carrierLogAccNo);
////            carrierBill.setCrProv(carrierAccountBook.getProv());
//            carrierBill.setCrBankCode("");
//        }
//        payBillData.setCustomerBill(customerBill);
//        payBillData.setShippingNoteBill(shippingNoteBill);
//        payBillData.setDriverBill(driverBill);
//        payBillData.setCarrierBill(carrierBill);
//
//        payBillData.setShippingNote(hyShippingNote);
//        return payBillData;
//    }

}
